<template>
	<view class="box">
		<!-- 使用记录 -->
		<view class="cord" :class="list.length>0?'bgc':''">
			<!-- <text @click="goCord">使用记录＞</text> -->
		</view>
		<!-- 空 -->
		<view class="none" v-if="!list.length">
			<view class="none-img f-w">
				<image src="https://jw.xzsw2021.com/static/big/icon_222@2x.png" mode=""></image>
			</view>
			<view class="f30 tr c666">暂时没有免运费券哦</view>
		</view>
		<!-- 列表 -->
		<view class="list" v-else>
			<view class="card flex" v-for="(item,index) of list" :key="index">
				<view class="left">
					<view class="price">￥<text class="f40 bold">{{item.coupon_price}}</text></view>
					<view class="tj f24">满{{item.use_min_price}}可用</view>
				</view>
				<view class="right">
					<view class="one">{{item.coupon_title}}</view>
					<view class="two f24" v-if="item.end_time">{{item.create_time.slice(0,10)}} -
						{{item.end_time.slice(0,10)}}
					</view>
					<view class="two f24" v-else>{{item.create_time.slice(0,10)}}</view>
					<view class="three flex">
						<view>
							<view class="desc" :class="!item.look?'hide-line':''">{{item.desc}}</view>
						</view>
						<view class="icon" @click="zhankai(index)" v-if="item.desc.length>17">
							<image src="https://jw.xzsw2021.com/static/img/icon_62@2x.png" mode="" v-if="!item.look">
							</image>
							<image src="https://jw.xzsw2021.com/static/img/icon_63@2x.png" mode="" v-else></image>
						</view>
					</view>
					<!-- 立即领取 -->
					<view class="lingqu" @click="gotoCounpShop(item)">
						去使用
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getUserCouponListApi
	} from '@/api/coupon.js'
	export default {
		data() {
			return {
				list: [],
				search: {
					page: 1,
					limit: 15,
					statusTag: 1,
					type_2: 2
				}
			}
		},
		onReachBottom() {
			this.search.page += 1
			this.couponList()
		},
		created() {
			this.couponList()
		},
		methods: {
			couponList() {
				getUserCouponListApi(this.search).then(res => {
					this.list.push(...res.data.list)
				}).catch(err => {

				})
			},


			// 使用记录
			goCord() {
				console.log('使用记录');
				uni.navigateTo({
					url: '/pages/user/mycoupons/freefieight/record/record'
				})
			},
			// 展开
			zhankai(index) {
				this.list[index].look = !this.list[index].look;
			},

			/**
			 * 去消费
			 * @param {Object} item
			 */
			gotoCounpShop(item) {
				uni.navigateTo({
					url: `/pages/client/shop/shop?id=${item.mer_id}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		.tab {
			height: 96rpx;
			padding: 0 100rpx;
		}

		.cord {
			padding: 30rpx;
			font-size: 26rpx;
			text-align: right;
			color: #F45E14;
		}

		.bgc {
			background-color: #F5F5F5;
		}

		.none {
			.none-img {
				margin: 148rpx auto 80rpx;
				width: 376rpx;
				height: 329rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.list {
			min-height: calc(100vh - 96rpx);
			background-color: #F5F5F5;
			padding: 0 30rpx 30rpx;
			box-sizing: border-box;

			.card {
				position: relative;
				margin-bottom: 20rpx;
				width: 690rpx;
				// height: 186rpx;
				padding: 23rpx 28rpx 23rpx 0;
				background: #FFFFFF;
				border-radius: 10rpx;
				box-sizing: border-box;

				.left {
					flex-shrink: 0;
					width: 160rpx;
					height: 160rpx;
					border-right: 1rpx dashed #CCCCCC;
					text-align: center;
					color: #F83535;

					.price {
						margin-top: 28rpx;
					}

					.tj {
						margin-top: 6rpx;
						color: #666;
					}
				}

				.right {
					position: relative;
					flex: 1;
					padding-right: 30rpx;
					margin-left: 30rpx;
					font-size: 28rpx;

					.two {
						margin: 28rpx 0;
						color: #666;
					}

					.three {
						color: #999;
						font-size: 24rpx;
						overflow: hidden;

						.desc {
							flex: 1;
							width: 420rpx;
						}

						.icon {
							flex-shrink: 0;
							margin-left: 20rpx;
							width: 26rpx;
							height: 14rpx;

							image {
								width: 100%;
								height: 100%;
							}
						}
					}

					.lingqu {
						position: absolute;
						right: 30rpx;
						top: 56rpx;
						width: 130rpx;
						height: 44rpx;
						line-height: 44rpx;
						text-align: center;
						background: #FFFFFF;
						border: 1rpx solid #F83535;
						border-radius: 22rpx;
						font-size: 26rpx;
						color: #F83535;
					}

					.get {
						border: 1rpx solid #ccc;
						color: #666;
					}
				}
			}
		}
	}
</style>
